//
//  FundView.m
//  项目三
//
//  Created by rimi on 15/10/9.
//  Copyright (c) 2015年 rimi. All rights reserved.
//

#import "FundView.h"
#import "JLCollectionViewCell.h"
#import "FunDetail.h"

static NSString*const kUICollectionViewCellIdentifier = @"FundCell";

@interface FundView () <UICollectionViewDataSource,UICollectionViewDelegate> {

    FunDetail *_fundDetailView;
}

@property (nonatomic, strong) UICollectionView *collectionView;

- (void)initializeUserInterface; /**< 初始化用户界面 */

@end

@implementation FundView

#pragma mark - init
- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self initializeUserInterface];
    }
    return self;
}
- (void)initializeUserInterface {

    [super initializeUserInterface];
    [self addSubview:self.collectionView];
}
#pragma mark - <UICollectionViewDataSource,UICollectionViewDelegate>
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    
    return 2;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return 4;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    JLCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kUICollectionViewCellIdentifier forIndexPath:indexPath];
    
    
    return cell;
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    
    return UIEdgeInsetsMake(0, 88, 20, 88);
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {

    if (!_fundDetailView) {
        _fundDetailView = [[FunDetail alloc] init];
    }
    if (![self.subviews containsObject:_fundDetailView]) {
        [self addSubview:_fundDetailView];
    }
}
#pragma mark - getter
- (UICollectionView *)collectionView {

    if (!_collectionView) {
        
        UICollectionViewFlowLayout *collectionViewFlowLayout = [[UICollectionViewFlowLayout alloc] init];
        collectionViewFlowLayout.itemSize = CGSizeMake(241, 307);
        collectionViewFlowLayout.minimumInteritemSpacing = 50;
        collectionViewFlowLayout.minimumLineSpacing = 23;
        
        _collectionView = [[UICollectionView alloc] initWithFrame:DHFlexibleFrame(CGRectMake(0, 64, 708, 800)) collectionViewLayout:collectionViewFlowLayout];
        _collectionView.backgroundColor = COLOR(205, 205, 205, 1);
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        [_collectionView registerNib:[UINib nibWithNibName:@"JLCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:kUICollectionViewCellIdentifier];
    }
    return _collectionView;
}
@end
